package com.edu.controller;

import com.edu.bean.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;
import java.util.Map;

/*
 * @Author:princess
 * @Date 2023/11/27 11 27 18:58
 *
 */
@Controller
public class JsonController01 {
    @RequestMapping("/json/backAUser")
    @ResponseBody
    public Object backAUser(){
        User user = new User();
        user.setUserId(1);
        user.setUsername("zhangsan");
        user.setPassword("123456");
        user.setSex("male");
        user.setBirthday(new Date());
        return user;
    }

    /**
     * 前端发送的数据格式为data：{msg:"hello world"}
     * @param msg
     * @return
     */
    @RequestMapping("/json/getAString")
    @ResponseBody
    public Object getAString(String msg){
        System.out.println(msg);
        return "访问成功";
    }

    @RequestMapping("/json/getAString2")
    @ResponseBody
    public Object getAString2(@RequestBody String msg){
        System.out.println(msg);
        return "访问成功";
    }

    @RequestMapping("/json/getAUser")
    @ResponseBody
    public Object getAUser(User user){
        System.out.println(user);
        return "访问成功";
    }

    @RequestMapping("/json/getAUser2")
    @ResponseBody
    public Object getAUser2(@RequestBody User user){
        System.out.println(user);
        return "访问成功";
    }

    @RequestMapping("/json/getAMap")
    @ResponseBody
    public Object getAMap(@RequestBody Map map){
        System.out.println(map);
        return "访问成功";
    }

    @RequestMapping("/json/getAList")
    @ResponseBody
    public Object getAList(@RequestBody List<User> users){
        for (User user : users) {
            System.out.println(user);
        }
        return "访问成功";
    }

    @RequestMapping("/json/backUsers")
    @ResponseBody
    public Object backUsers(){
        User user = new User();
        user.setUserId(1);
        user.setUsername("zhangsan");
        user.setPassword("123456");
        user.setSex("male");
        user.setBirthday(new Date());
        return user;
    }
}
